﻿//<TunynetCopyright>
//--------------------------------------------------------------
//<copyright>青岛拓宇网络科技有限公司 2005-2008</copyright>
//<version>V0.5</verion>
//<createdate>2008-2-23</createdate>
//<author>mazq</author>
//<email>mazq@tunynet.com</email>
//<log date="2008-2-23">创建</log>
//--------------------------------------------------------------
//</TunynetCopyright>


using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;

namespace ChinaCustoms.Qingdao.Workflow.Supports
{
    /// <summary>
    /// 任务查询类
    /// </summary>
    public class TaskQuery
    {
        /// <summary>
        /// 任务名称
        /// </summary>
        public string TaskName = string.Empty;

        /// <summary>
        /// 任务类型
        /// </summary>
        public string TaskType = string.Empty;

        /// <summary>
        /// ApplicationCodeName数组
        /// </summary>
        public string[] ApplicationCodeNames = null;

        /// <summary>
        /// 发起人UserName
        /// </summary>
        public string SponsorUserName = string.Empty;

        /// <summary>
        /// 任务状态
        /// </summary>
        public TaskStatus? TaskStatus = null;

        /// <summary>
        /// 日期范围
        /// </summary>
        public DateScope? DateScope = null;

        public int PageIndex = 0;
        public int PageSize = 20;

        /// <summary>
        /// 是否分页，默认值为false，表示需要不页
        /// </summary>
        public bool AllowPaging = false;

        /// <summary>
        ///  最大返回记录数
        /// </summary>
        /// <remarks>
        /// MaxRecords = -1没有限定
        /// </remarks>
        public int MaxRecords = 5000;

        /// <summary>
        /// 排序字段
        /// </summary>
        public SortTaskBy SortBy = SortTaskBy.CreateDate;

        /// <summary>
        /// 排序方向
        /// </summary>
        public SortOrder SortOrder = SortOrder.Descending;

        //-------------------------------------------------------------------------
        //如果要获取跟某些 WorkItem相关联的Task,需要配置以下属性
        
        /// <summary>
        /// 工作项的执行者登录名
        /// </summary>
        public string WorkItemExecutorUserName = string.Empty;

        /// <summary>
        /// 工作项的状态,可以有多个状态
        /// </summary>
        public WorkItemStatus[] WorkItemStatuses = null;
        //-------------------------------------------------------------------------

        public string CacheKey
        {
            get
            {
                string appCodeNamesKey = string.Empty;
                if (ApplicationCodeNames != null && ApplicationCodeNames.Length > 0)
                    appCodeNamesKey = string.Join(",", ApplicationCodeNames);

                return string.Format("Tasks::TaskStatus:{0}-DateScope:{1}-TaskName:{2}-ApplicationCodeName:{3}-SponsorUserName:{3}-PI:{4}-PS:{5}-IP:{6}-MaxRecords:{7}-TaskType:{8}",
                    TaskStatus.HasValue ? (int)TaskStatus : -1, this.DateScope.HasValue ? (int)DateScope : -1, TaskName, appCodeNamesKey, SponsorUserName, PageIndex, PageSize, AllowPaging, MaxRecords,TaskType);
            }
        }

    }

    public enum SortTaskBy
    {
        TaskName=1,
        TaskType=2,
        CreateDate=3,
        LastUpdateDate=4,
        ApplicationCodeName=5,
        SponsorUserName=6
    }
}
